package com.first.orange.controller;

import com.first.orange.beans.PageSupport;
import com.first.orange.beans.Product;
import com.first.orange.service.wangshengwang.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created on 2021/7/5.
 * <p>
 * Author: wsw
 * <p>
 * Description:
 */
@Controller
public class SearchController {
    @Autowired
    private ProductService productService;
    @RequestMapping("/search")
    public String productList(@RequestParam(required = false)String searchMsg,Map<String,Object> map){
        map.put("brands",productService.queryProductBrand());
        map.put("kinds",productService.queryProductKind());
        map.put("searchMsg",searchMsg);
        return "home/search";
    }
    @ResponseBody
    @RequestMapping("/searchCount")
    public PageSupport searchCount(@RequestParam("searchMsg")String searchMsg, @RequestParam(required = false) String brandId, @RequestParam(required = false) String kindId){
        PageSupport pageSupport=new PageSupport();
        pageSupport.setTotalCount(productService.queryProductCount(searchMsg,brandId,kindId));
        return pageSupport;
    }
    @ResponseBody
    @RequestMapping("/searchByCategory")
    public List<Product> productListByCatrgory(@RequestParam("searchMsg")String searchMsg,@RequestParam(required = false) String brandId,@RequestParam(required = false) String kindId,@RequestParam int currPageNo){
        System.out.println(productService.queryProductListByCategory(searchMsg,brandId,kindId,currPageNo));
        return productService.queryProductListByCategory(searchMsg,brandId,kindId,currPageNo);
    }

    @RequestMapping("/toProductInfo")
    public String toproductInfo(@RequestParam String productId ,Map<String,Object> map){
        map.put("pictures",productService.queryProductPictureByProductId(productId));
        map.put("product",productService.queryProductById(productId));
        map.put("tastes",productService.queryProductTaste());
        System.out.println(productService.queryProductTaste());
        map.put("packs",productService.queryProductPack());
        return "home/introduction";
    }
}
